def searchWord(s):
    charUpper = [chr(i+ord('A')) for i in range(26)]
    charLower = [chr(i+ord('a')) for i in range(26)]
    chars = charUpper + charLower
    words=[]
    word =[]
    ifInAWord = False
    for i in s:
        if (i in chars):
            if not ifInAWord:
                ifInAWord = True
            word.append(i)
        else:
            if ifInAWord:
                s = "".join(word)
                words.append(s)
                word.clear()
                ifInAWord = False
    else:
        if ifInAWord:
            s = "".join(word)
            words.append(s)
    return words

# counter
counter = {}
n = int(input())
for i in range(n):
    sentence = input()
    words = searchWord(sentence)
    for aword in words:
        word = aword.lower()
        if word in counter:
            counter[word] = counter[word] + 1
        else:
            counter[word] = 1
#sort
keys = list(counter.keys())
keys.sort()
#show
for key in keys:
    print(f"{key} {counter[key]}")
